import time
from conf import featherGuard as conf
from machine import reset

###简单移动平均滤波算法
class WindowSmoother:
    Buffer = list()
    RawDataPool = list()
    def __add__(self,obj: int or float):
        self.Buffer.append(obj)
    def __clean__(self):
        self.Buffer = Buffer[conf.WINDOWLENGTH:]
    def __smooth__(self):#外部
        return sum(self.Buffer) / len(self.Buffer)
    def __record__():
        timeline.append(time.ticks_ms())
    def loaddata(self,data):
        __add__(data)
        if len(Buffer) < conf.WINDOWLENGTH:
            self.RawDataPool.append(data)
        else:#一开始没到窗口长度，到了之后平滑一次作为一个数据（浓缩，嘿嘿）,然后归零采样率除以窗口长才是实际采样率
            self.RawDataPool.append(__smooth__(self.Buffer))
            __clean__()
            __record__()
    def unloaddata(self):
        tmp = self.RawData[0]
        self.RawData = self.RawData[1:]
        return tmp